package com.ruoyi.wms.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.mapper.StockPdaInMapper;
import com.ruoyi.wms.domain.StockPdaIn;
import com.ruoyi.wms.service.IStockPdaInService;

/**
 * PDA入库库存Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-28
 */
@Service
public class StockPdaInServiceImpl implements IStockPdaInService {
    @Autowired
    private StockPdaInMapper stockPdaInMapper;

    /**
     * 查询PDA入库库存
     *
     * @param id PDA入库库存主键
     * @return PDA入库库存
     */
    @Override
    public StockPdaIn selectStockPdaInById(String id) {
        return stockPdaInMapper.selectStockPdaInById(id);
    }

    /**
     * 查询PDA入库库存列表
     *
     * @param stockPdaIn PDA入库库存
     * @return PDA入库库存
     */
    @Override
    public List<StockPdaIn> selectStockPdaInList(StockPdaIn stockPdaIn) {
        return stockPdaInMapper.selectStockPdaInList(stockPdaIn);
    }

    /**
     * 新增PDA入库库存
     *
     * @param stockPdaIn PDA入库库存
     * @return 结果
     */
    @Override
    public int insertStockPdaIn(StockPdaIn stockPdaIn) {
        stockPdaIn.setId(MD5Utils.md5(stockPdaIn.getTaskNum()));
        stockPdaIn.setCreateUser(SecurityUtils.getUsername());
        stockPdaIn.setCreateDate(DateUtils.getCurrentTime());
        stockPdaIn.setUpdateDate( DateUtils.getCurrentTime());
        return stockPdaInMapper.insertStockPdaIn(stockPdaIn);
    }

    /**
     * 修改PDA入库库存
     *
     * @param stockPdaIn PDA入库库存
     * @return 结果
     */
    @Override
    public int updateStockPdaIn(StockPdaIn stockPdaIn) {
        int updateResult = 0;
        if (StringUtils.isEmpty(stockPdaIn.getId())) {
            updateResult = insertStockPdaIn(stockPdaIn);
        }
        stockPdaIn.setUpdateDate( DateUtils.getCurrentTime());
        updateResult = stockPdaInMapper.updateStockPdaIn(stockPdaIn);
        if (0 == updateResult) {
            updateResult = insertStockPdaIn(stockPdaIn);
        }


        return updateResult;

    }

    /**
     * 批量删除PDA入库库存
     *
     * @param ids 需要删除的PDA入库库存主键
     * @return 结果
     */
    @Override
    public int deleteStockPdaInByIds(String[] ids) {
        return stockPdaInMapper.deleteStockPdaInByIds(ids);
    }

    /**
     * 删除PDA入库库存信息
     *
     * @param id PDA入库库存主键
     * @return 结果
     */
    @Override
    public int deleteStockPdaInById(String id) {
        return stockPdaInMapper.deleteStockPdaInById(id);
    }
}
